<?php

class Application_Model_TodoTask extends Application_Model_DomainObject {

      protected $_id;
      protected $_objectType;
      protected $_objectId;
      protected $_priority;
      protected $_title;
      protected $_dateCreated;
      protected $_expectTime;
      protected $_status;
      protected $_creator;
      protected $_operator;
      protected $_content;

      /**
       * 优先级 一般
       */
      const Priority_A = 1;

      /**
       * 优先级 较低
       */
      const Priority_B = 2;

      /**
       * 优先级 较高
       */
      const Priority_C = 3;

      /**
       * 优先级 最高
       */
      const Priority_D = 4;

      /**
       * 未开始状态
       */
      const Object_Add = 1;

      /**
       * 开始状态
       */
      const Object_Appoint = 2;

      /**
       * 完成状态
       */
      const Object_Complete = 3;

      /**
       * 关闭状态
       */
      const Object_Close = 4;
      /**
       * 登陆名等于创建人和指派人
       */
      const Name_first = 1;
      /**
       * 登录名等于创建人
       */
      const Name_second =2;
      /**
       * 登录名等于指派人
       */
      const Name_third = 3;
      /**
       * 登陆名既不是创建人也不是指派人
       */
      const Name_forth =0;
      /**
       * 
       * @param type $objectSearch
       * @param type $pagesize
       * @param type $pageindex
       * @return type object  列表页
       */
      public static function getFilter($objectSearch, $pagesize, $pageindex) {
//                  var_dump($objectSearch->getSearchFileds());
            return Application_Model_TodoTask::getDao()->queryPage($objectSearch->getSearchFileds(), 'id desc', $pagesize, $pageindex);
      }

      public static function byUserBlockGetAllByObjectTypeId($objectType, $objectId) {
            return self::getDao()->queryAll(array("objectType = " => $objectType, " and objectId = " => $objectId), 'id desc');
      }

      /**
       * 
       * @return type 状态值
       * 
       */
      public static function getObjectStep() {
            return array(
                Application_Model_TodoTask::Object_Add => array("已添加", "未添加"),
                Application_Model_TodoTask::Object_Appoint => array("已指派", "待指派"),
                Application_Model_TodoTask::Object_Complete => array("已完成", "未完成"),
                Application_Model_TodoTask::Object_Close => array("关闭", "等待关闭"),
            );
      }
      public static function getCountBySolve($userId)
        {
            return self::getDao()->count(array("operator = "=>$userId," and status != "=>  self::Object_Complete));
        }

      /**
       * 
       * @return type 优先级
       */
      public function getPriorityValue() {
            switch ($this->_priority) {
                  case self::Priority_A:
                        return '一般';
                        break;
                  case self::Priority_B:
                        return '较低';
                        break;
                  case self::Priority_C:
                        return '较高';
                        break;
                  case self::Priority_D:
                        return '最高';
                        break;
                  default:
                        break;
            }
      }

      /**
       * 
       * @return type object
       * 返回该类型的名称
       */
      public function getObjectName() {
            $id = $this->_objectType;
            $ret = Application_Model_DomainobjectType::load($id);
            return $ret;
      }

       /**
       * 
       * @return type INT STATUS
       * 状态值
       */
      public static function getObjectIdStatus($status) {
            switch ($status) {
                  case self::Object_Add:
                        return ('未开始');
                  case self::Object_Appoint:
                        return ('进行中');
                  case self::Object_Complete:
                        return ('已完成');
                        break;
                  default :
                        break;
            }
      }

      public function getObjectStatus() {
            switch ($this->_status) {
                  case self::Object_Add:
                        return ('未开始');
                  case self::Object_Appoint:
                        return ('进行中');
                  case self::Object_Complete:
                        return ('已完成');
                        break;
                  default :
                        break;
            }
      }

      /**
       * 
       * @return type
       * 返回管理员名字
       */
      public function getUserName() {
            $id = $this->_creator;
            $ret = Application_Model_adminuser::load($id);
            $ret1 = $ret ? $ret : "";
            return $ret1;
      }

      public function getobjectTracking() {
            $id = $this->_objectId;
            $ret = Application_Model_adminuser::load($id);
            return $ret;
      }

      public function getTracking() {
            $id = $this->_objectId;
            $type = $this->_objectType;
            return $arr = array(
                '1' => Application_Model_Tracking::getOneByObjectTypeIdOperateType($type, $id, Application_Model_TodoTask::Object_Add),
                '2' => Application_Model_Tracking::getOneByObjectTypeIdOperateType($type, $id, Application_Model_TodoTask::Object_Appoint),
                '3' => Application_Model_Tracking::getOneByObjectTypeIdOperateType($type, $id, Application_Model_TodoTask::Object_Complete)
            );
      }
      public function getEqualName(){
             $name = Uuch_Util::getUserNikeName();
            if($name != $this->_creator && $name != $this->_operator)
            {
                  return 0;
            }
            if($name == $this->_creator && $name == $this->_operator)
            {
                  return 1;
            }
            switch (Uuch_Util::getUserNikeName()){
                  case $this->_creator:
                        $ret = 2;
                        break;
                  case $this->_operator:
                        $ret = 3;
                        break;
                  default :
                        $ret = 0;
                        break;
            }
            return $ret;
      }

}
